package com.abl.tomcat.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 环境变量
 * 读取 server.properties
 */
public class Property {
    private static final Properties properties = new Properties();

    static {
        InputStream resourceAsStream = FileKit.getResourceAsStream("/server.properties");
        try {
            properties.load(resourceAsStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static int getPort() {
        Object orDefault = properties.getOrDefault("server.port", "8090");

        if (orDefault == null || orDefault.equals("")) throw new RuntimeException("端口号配置错误，请检查 server.properties");

        return Integer.parseInt(orDefault.toString());
    }

}
